package com.yyz.zjjcms.controller.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.support.ModelAndViewContainer;

import com.yyz.zjjcms.model.User;
import com.yyz.zjjcms.service.CommonService;



@Controller
@RequestMapping("/admin")
public class CommonController extends AdminController{
	@Resource
	CommonService commonService;
	@RequestMapping(value={"/","/login"},method=RequestMethod.GET)
	public String loginGET(ModelAndViewContainer mavContainer){
		return getResponseUrl("/login");
	}
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String loginPOST(HttpSession session,HttpServletRequest request, Model m ,String username,String userpassword){
		User user = commonService.login(username, userpassword);
		if(user!=null){
			session.setAttribute("user", user);
			return getResponseUrl("/index");
		}else{
			m.addAttribute("message", "用户名或者密码错误");
			return getResponseUrl("/login");
		}
	}
	@RequestMapping(value="/welcome")
	public String welcome(ModelAndViewContainer mavContainer){
		return getResponseUrl("/welcome");
	}
	@RequestMapping(value="/user")
	public String user(ModelAndViewContainer mavContainer){
		return getResponseUrl("/user");
	}
	
}
